package com.iflytek.hive.need5;


import org.apache.hadoop.io.WritableComparable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class QuatOrderBean implements WritableComparable<QuatOrderBean> {
    private String date;
    private String quat;
    private String orderid;
    private double amount;

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getQuat() {
        return quat;
    }

    public void setQuat(String quat) {
        this.quat = quat;
    }

    public String getOrderid() {
        return orderid;
    }

    public void setOrderid(String orderid) {
        this.orderid = orderid;
    }

    public double getAmount() {
        return amount;
    }

    public void setAmount(double amount) {
        this.amount = amount;
    }

    public void set(String date,String quat,String orderid,double amount) {
        this.date = date;
        this.quat =quat;
        this.orderid =orderid;
        this.amount =amount;
    }

    @Override
    public int compareTo(QuatOrderBean o) {
        // 判断年份是否相同
        int result = this.date.substring(0, 4).compareTo(o.date.substring(0, 4));
        if (result == 0) {
            // 判断季度是否相同
            int result1 = this.quat.compareTo(o.quat);
            if (result1 == 0) {
                // 订单金额倒序
                return this.amount - o.getAmount() > 0 ? -1 : (this.amount - o.getAmount() < 0 ? 1 : 0);
            }
            return result1;
        }
        return result;
    }


    @Override
    public void write(DataOutput out) throws IOException {
        out.writeUTF(date);
        out.writeUTF(quat);
        out.writeUTF(orderid);
        out.writeDouble(amount);
    }

    @Override
    public void readFields(DataInput in) throws IOException {
        date = in.readUTF();
        quat = in.readUTF();
        orderid = in.readUTF();
        amount = in.readDouble();
    }
    @Override
    public String toString() {
        return date+","+quat+","+orderid+","+amount;
    }
}
